import React from 'react'

import { Tooltip } from 'antd'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import AddEditModal from '#cpt/temp/AddEditModal'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
import Delete from '#cpt/temp/Delete'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '中文标题',		name: 'title' },
			{ label: '英文标题',		name: 'title_en' },
			{ label: '关键词',		name: 'keyword' },
			{ label: '中文内容',		name: 'content' },
			{ label: '英文内容',		name: 'content_en' },
		],
		// 提交表单列表
		formData : [
			{ label: '中文标题',		name: 'title', 		full:true, required:true },
			{ label: '英文标题',		name: 'title_en', 	full:true },
			{ label: '关键词',		name: 'keyword', 	full:true, required:true },
			{ label: '排序',			name: 'sort', 		full:true, type:'number'  },
			{ label: '中文内容',		name: 'content', 	full:true, required:true, type:'textarea' },
			{ label: '英文内容',		name: 'content_en', full:true, type:'textarea' },
		]
	}
	
	model = {}
	
	componentDidMount(){
		if(window.isInit){
			this.fetch()
		}
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'knowledge-base/index')
	
	// 表单
	cols = [
		{ title: '中文标题', 	dataIndex: 'title', 			width:200 },
		{ title: '英文标题', 	dataIndex: 'title_en', 			width:200 },
		{ title: '关键词', 		dataIndex: 'keyword', 			width:150 },
		{ title: '中文内容', 	dataIndex: 'content', 			width:200, render: text => <Tooltip overlayClassName='table-tooltip' placement='leftTop' title={text}><div className='omits-1'>{text}</div></Tooltip>},
		{ title: '英文内容', 	dataIndex: 'content_en', 		width:200, render: text => <Tooltip overlayClassName='table-tooltip' placement='leftTop' title={text}><div className='omits-1'>{text}</div></Tooltip> },
		{ title: '排序', 		dataIndex: 'sort', 				...$fn.table.num },
		TableControls.controls.call(this)
	]
	// 表格操作按钮
	table_controls = (text,{ uuid }) => {
		return [
			TableControls.edit.call(this, 'knowledge-base/info', { uuid }),				// 编辑
			this.onDel([ uuid ]),															// 删除
		]
	}
	// 操作按钮
	controls = () => {
		return [
			Controls.add.call(this),			// 添加
			this.onDel(),						// 删除
		]
	}
	// 删除
	onDel = uuid => Delete.call(this, 'knowledge-base/delete', { uuid, isKeys: !uuid })
	
	render(){
		return (
			<>
				<Page title='病理知识库管理' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this,{isInit:window.isInit}) }
				</Page>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ api: 'knowledge-base/add', editApi:'knowledge-base/edit' }) }
			</>
		)
	}
}

export default Index